package com.bamboo.mcp.server.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springaicommunity.mcp.annotation.McpTool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class WeatherService {
    private static final Logger logger = LoggerFactory.getLogger(WeatherService.class);

    private String apiKey = "fce22bacc3945df5874c77b1994060fb";

    private static final String GAODE_WEATHER_API = "https://restapi.amap.com/v3/weather/weatherInfo";

    @McpTool(name = "getWeather", description = "获取城市的天气")
    public String getWeather(@ToolParam(description = "城市名称，如深圳市") String city) {
        logger.info("getWeather,city:{}", city);
        RestTemplate restTemplate = new RestTemplate();
        String url = GAODE_WEATHER_API + "?city=" + city + "&key=" + apiKey;
        return restTemplate.getForObject(url, String.class);
    }
}